package com.titan.demo.camel.sample.eip.使用enrich实现信息合并.camel.route;

import java.util.List;

import org.apache.camel.Exchange;
import org.apache.camel.processor.aggregate.AggregationStrategy;

public class MyAggregationStrategy implements AggregationStrategy {
	@Override
	public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
	    if (oldExchange == null) {
		    // the first time we aggregate we only have the new exchange,
		    // so we just return it
		    return newExchange;
	    }

	    List<Integer> lio = oldExchange.getIn().getBody(List.class);
	    List<Integer> lin = newExchange.getIn().getBody(List.class);
	    System.out.println("[AggregationStrategy] old.size="+lio.size()+"  new.size="+lin.size());
	    
	    for(Integer i : lin){
	        lio.add(i);
	    }

	    oldExchange.getIn().setBody(lio);
	    return oldExchange;
	}
}
